***Recreate results of paper after running modified code (based on files authors sent us)***Use dataset: Births Datasets/DLHS3 Births.dta  (PRE-Matching dataset)
**Setupclearclear mataclear allset more offset mem 800mset maxvar 5000

set matsize 2000pause on//global d "\Volumes\FreeAgent GoFlex Drive\Natalie\Research\India Research\Surveys\"//global f "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Data\"//global d "F:\Natalie\Research\India Research\Surveys\DLHS_RCH3\"global f "F:\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Data\"use "${f}Births Datasets/DLHS3 Births.dta", clearcount  //NC: 187,338 obs 

//Prep dataset first (based on authors' matching do file

// Attended birth (in-facility birth or skilled birth attendance)
gen ab = .
replace ab = 1 if ((ifb == 1)|(sba == 1))
replace ab = 0 if ((ifb == 0)&(sba == 0))


// Neonatal mortality or still birth
gen nmsb = .
replace nmsb = 1 if ((sb == 1)|(nnm == 1))
replace nmsb = 0 if ((sb == 0)&(nnm == 0))


/* Make variables that don't yet exist: */
/* Skilled birth attendance (delivery in a facility, or outside of a facility but with a skilled birth attendant present) */
capture drop ab
gen ab = .
replace ab = 1 if ((ifb == 1)|(sba == 1))
replace ab = 0 if ((ifb == 0)&(sba == 0))
/* Alternate skilled birth attendance (delivery in a facility, or outside of a facility but with a skilled attendant present) with the other, more restricted */
/* definition of skilled birth attendant. */
gen alt_ab = .
replace alt_ab = 1 if ((alt_sba == 1)|(ifb == 1))
replace alt_ab = 0 if ((alt_sba == 0)&(ifb == 0))
/* Stillbirth/Neonatal death (infant is either still-born, or born alive but dies within first month of life) */
capture drop nmsb
gen nmsb = .
replace nmsb = 1 if ((sb == 1)|(nnm == 1))
replace nmsb = 0 if ((sb == 0)&(nnm == 0))
/* Late neonatal mortality: */
gen lnm = . 
replace lnm = 1 if (nnm == 1)&(enm == 0)
replace lnm = 0 if (nnm == 0)|(enm == 1)

**********************************************************************Step 1: Basic characteristics of the data				  *********************************************************************
count /*187338 */
tab jsy, m  /*122 missing */count if jsy != .  /* 187 216*/count if jsy!= . & nb != .  /*186 449 Note: nb is number of births - parity*/**Tests to check if we can find why we have extra obs**Note: High focus state and Northeastern state vars already created

*state_cat = 1 for High-focus state
*state_cat = 2 for Northeastern State
*state_cat = 3 for Other States
count if state_cat == 1 & jsy != .   /*114 522 should be 112 179 */ count if state_cat == 2 & jsy != .    /*13 254 should be 12 757*/count if state_cat == 3 & jsy != .    /*59 440 should be 57 918*/keep if  ((dlhs == 3)&(cmcage <= 12)) /*NC: have taken this out */



*******************************************************************



*** Get data ready for logistic regressions			  ***



******************************************************************


// dropping observations for which JSY or the outcome is missing:
//NC: I am not dropping enm, lnm, nmsb but including nnm

drop if jsy==.   //This only deletes 51 obs (or 122 in full dataset)
/*
drop if anc3 == .  //nothing deleted (or 3 in full dataset)
drop if ifb == .  //174 obs deleted  (or 538 in full dataset)
drop if pnm == .   // 11 obs deleted (or 35 in full dataset)
drop if enm == .  //951 obs deleted  (or 1742 in full dataset)
drop if lnm == . //nothing deleted (NC)
*drop if nnm == . // (drops 1742 in full dataset)
drop if ab == .  // 589 obs deletted (or 2060 in full dataset)
*drop if nmsb ==.  //nothing deleted
*/

count /* 187 216 if have deleted missing JSY; Their Table 1 value is 182 869 */


*******************************************************************

***Step 2: Try to re-create national level results (Figure 3)  ***

******************************************************************

***PHASE 1: On entire dataset

*Graph A 
replace distfac_cat = 0 if urban == 1
table distfac_cat, c(mean jsy sem jsy)  

*Graph B
table mateduc_cat, c(mean jsy sem jsy)

*Graph C
table caste, c(mean jsy sem jsy)
*Graph D
table  nb_cat, c(mean jsy sem jsy)
*Graph E
table dlhs3_country_quintile, c(mean jsy sem jsy)
*Graph F
table  matage_cat, c(mean jsy sem jsy)***PHASE 2: Restricted to births in last 12 months

*Graph A 
table distfac_cat if cmcage <= 12, c(mean jsy sem jsy)  

*Graph B
table mateduc_cat if cmcage <= 12, c(mean jsy sem jsy)

*Graph C
table caste if cmcage <= 12, c(mean jsy sem jsy)

*Graph D
table  nb_cat if cmcage <= 12, c(mean jsy sem jsy)

*Graph E
table dlhs3_country_quintile if cmcage <= 12, c(mean jsy sem jsy)

*Graph F
table  matage_cat if cmcage <= 12, c(mean jsy sem jsy)
*******************************************************************

***Step 3: Try to re-create state level uptake (Figure 2)  *** 

******************************************************************

/*unrestricted*/
graph bar jsy, over(state_code_dlhs3, sort(1) descending) 

/*Restricted*/
graph bar jsy if  cmcage <= 12, over(state_code_dlhs3, sort(1) descending) 

*Look at all facility-level deliveries (JSY and not JSY) - restricted only

graph bar ifb jsy if  cmcage <= 12, over(state_code_dlhs3, sort(2) descending) 

gen ifb_nojsy = ifb - jsy
replace ifb_nojsy = 0 if ifb_nojsy <0

graph bar jsy ifb_nojsy if  cmcage <= 12, over(state_code_dlhs3, sort(1) descending) stack
graph bar jsy ifb_nojsy if  cmcage <= 12, over(state_code_dlhs3, sort(ifb) descending) stack


**********************************************************************Step 4: Run multivariate logistic regression to re-create 	***

***	Table 1 looking at the association btwn receipt of JSY		*********************************************************************

gen dwu = dweight*dm_coef
gen swu = dweight*sm_coef


/*gives the national level means for Table 2*/
mean anc3 ifb ab pnm  nnm [pweight=dwu] if cmcage <= 12

foreach var of varlist matage_cat nb_cat mateduc_cat dlhs3_country_decile caste religion urban DIST_mean_hh_p_income3 state_code_dlhs3 {
count if `var' == .
}

//there are 767 missings for nb_cat (used to be 0 live births, coded to .) and 62 missings for mateduc_cat

keep if nb_cat != . & mateduc_cat != .

count /* 186 387 (having dropped missing JSY, nb_cat, mateduc_cat*/


// add back in below? if anc3 != . & ifb != . & pnm != . & nnm != . & ab !=.

**National level results (n=182 869 target; me: 182 744)

        **Part 1: NON RESTRICTED DATA
char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on NATIONAL unmatched DLHS3 dataset..."

				di "running MV logit model for JSY uptake for NATIONAL LEVEL:"

				xi: logit jsy  `covar_list'  [pweight=dwu], or
	
				estimates store jsy
				 
	estout jsy using "F:\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_full dataset.txt", style(tab) cells("b se p") stats(N) eform replace
	//estout jsy using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_full dataset.txt", style(tab) cells("b se p") stats(N) eform replace


	
	    **Part 2: RESTRICTED DATA (only births in last 12 months)

char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on NATIONAL unmatched DLHS3 dataset, restricted to last 12 months...."

				di "running MV logit model for JSY uptake for NATIONAL LEVEL:"

				xi: logit jsy  `covar_list' if cmcage <= 12 [pweight=dwu], or
	
				estimates store jsy1
				 
	estout jsy1 using "F:\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_small dataset.txt", style(tab) cells("b se p") stats(N) eform replace
	//estout jsy1 using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_small dataset.txt", style(tab) cells("b se p") stats(N) eform replace

	
	
	    **Part 3: FURTHER RESTRICTED DATA (only births in last 8 months)

char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on NATIONAL unmatched DLHS3 dataset, restricted to last 8 months..."

				di "running MV logit model for JSY uptake for NATIONAL LEVEL:"

				xi: logit jsy  `covar_list' if cmcage <= 8 [pweight=dwu], or
	
				estimates store jsy2
				 
	estout jsy2 using "F:\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 25 April 2011 ORs_8 months dataset.txt", style(tab) cells("b se p") stats(N) eform replace
	//estout jsy2 using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_small dataset.txt", style(tab) cells("b se p") stats(N) eform replace

	
	    **Part 4: FURTHER RESTRICTED DATA (only births in last 6 months)

char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on NATIONAL unmatched DLHS3 dataset, restricted to last 6 months..."

				di "running MV logit model for JSY uptake for NATIONAL LEVEL:"

				xi: logit jsy  `covar_list' if cmcage <= 6 [pweight=dwu], or
	
				estimates store jsy3
				 
	estout jsy3 using "F:\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 25 April 2011 ORs_6 months dataset.txt", style(tab) cells("b se p") stats(N) eform replace
	//estout jsy3 using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 National- 19 April 2011 ORs_6 months dataset.txt", style(tab) cells("b se p") stats(N) eform replace

	
	
**High-focus states (n=112 179 target; me: 111 782)


            **Part 1: NON RESTRICTED DATA
char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on HIGH FOCUS unmatched DLHS3 dataset..."

				di "running MV logit model for JSY uptake for HIGH FOCUS STATES:"

				xi: logit jsy  `covar_list'  if state_cat == 1 [pweight=dwu], or
	
				estimates store jsy2
				 
	estout jsy2 using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 High Focus States- 15 April 2011 ORs_full dataset.txt", style(tab) cells("b se p") stats(N) eform replace


	
	        **Part 2: RESTRICTED DATA (only births in last 12 months)
	
	
char matage_cat[omit] 4
char caste[omit] 4
char state_code_dlhs3[omit] 9


local covar_list = "i.matage_cat i.nb_cat i.mateduc_cat i.dlhs3_country_decile i.caste i.religion urban DIST_mean_hh_p_income3 i.state_code_dlhs3"

disp "running logistic regression of JSY uptake by maternal age, number of births, maternal education, caste, religion, urban/rural, wealth deciles, district mean PI, and state fixed effects"
		
di "NATIONAL: conducting MV logistic regression on HIGH FOCUS unmatched DLHS3 dataset..."

				di "running MV logit model for JSY uptake for HIGH FOCUS STATES:"

				xi: logit jsy  `covar_list'  if state_cat == 1 [pweight=dwu], or
	
				estimates store jsy3
				 
	estout jsy3 using "\Volumes\FreeAgent GoFlex Drive\Natalie\PhD Health Policy\Classes\Gov 2001\Replication paper\Project\Results\Table 1 High Focus States- 15 April 2011 ORs_small dataset.txt", style(tab) cells("b se p") stats(N) eform replace

	
